/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.edu.ecnu.gis.client.model;

import cn.edu.ecnu.gis.client.ltapi.localsearch.LTLocalSearchRequest;
import cn.edu.ecnu.gis.client.ltapi.localsearch.LTLocalSearchRequestHandle;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONParser;

/**
 *
 * @author meflyup
 */
public class LocalSearchResult implements LTLocalSearchRequestHandle {
private JSONArray points =null;
public void search(String address,String city){
    LTLocalSearchRequest.search( "address", "上海",this );//默认城市用上海
}

    public void onRequestComplete(String result) {
        JSONObject searchResult = (JSONObject) JSONParser.parse(result);
        //JSONArray entries = (JSONArray) searchResult.get("entries");
        JSONArray searchPoints = (JSONArray) searchResult.get("searchPoints");

        //for (int i = 0; i < searchPoints.size(); i++) {
       //当前仅取出第一个搜索结果，仅作测试显示用
        for (int i = 0; i < 1; i++) {
            JSONObject item = (JSONObject) searchPoints.get(i);
//            JSONString id = (JSONString) item.get("id");
//            JSONString url = (JSONString) item.get("url");
//            JSONString name = (JSONString) item.get("name");
            setPoints((JSONArray) item.get("point"));
//            HTML html = new HTML("<a href='" + url.stringValue() + "' target='_blank'>" + name.stringValue() + "</a>");
//            html.setStyleName("News-Item");
        //list.add( html );
        }
    }

    public void onRequestFailed(String error) {
    //list.add( new HTML(error) );
    }

    public JSONArray getPoints() {
        return points;
    }

    public void setPoints(JSONArray points) {
        this.points = points;
    }
}
